<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller {
	
	public $WEB_SET;
	public $WEB_Language="english";
	
	
	function __construct()
     {

     	parent::__construct();
		
		
		
     	//按当前语言载入语言文件
     	if($this->session->userdata("lang")=="")
     	{
			$this->lang->load('info',$this->config->item("language"));
		}else
		{
			$this->lang->load('info',$this->session->userdata("lang"));
		}
		
		//加载网站设置
		$this->load->model("Agent_model");
		$this->WEB_SET=$this->Agent_model->load_websetinfo();
	
		$this->WEB_Language = $this->session->userdata("lang");
		
		//记录日志
		$this->load->model("Userlog_model");
		$this->Userlog_model->write_userlog();
		
		//设置了需要登陆后才能查询的话跳转到登陆界面

		if($this->WEB_SET["querylogin"] && !$this->session->userdata('user_in'))
		{
			redirect("user/login");	
		}

     }
	
	 //首页
	public function index()
	{
		
		$data = array();
	   	$data['css'][0] = '<link rel="stylesheet" type="text/css" href="'.site_url('css/validator.css').'" />';
	   	$data['title'] = $this->WEB_SET["WEB_WebsiteTitle_".lang("curlang")].
	   				$this->WEB_SET["WEB_WelcomeText_".lang("curlang")]."-".lang("home_title");
		
		//加载信息
		$this->load->model("Agent_model");
		$webtext=$this->Agent_model->get_agentbyweb();
		
		$this->load->model("Setting_model");
		$homeadv=$this->Setting_model->get_advContext("adv1",$this->WEB_SET["WEB_AgentCode"]);
		
	   	$data['importmsg'] =$webtext["tInformation_".lang("curlang")];	//重要消息
	   	$data['homeadv'] ="<img src=\"".site_url($homeadv->Context)."\" />";	//广告信息

	   	//设置航空公司下拉菜单
	   	$airoption =lang("aircompany");
	   	$airlist['']='=='.lang("home_allairline").'==';
	   	foreach ($airoption as $airid => $airname)
	   	{
	   		$airlist[$airid]=$airid.'-'.$airname;
	   	}

	   	$data['selairline']=form_dropdown('airline', $airlist, '','style="width:164px"');

	   	//语言文件
	   	$data['Find_a_Flight']	=lang("Find_a_Flight");
	   	$data['home_Flight_Type']=lang('home_Flight_Type');
		$data['home_From']       =lang('home_From');
		$data['home_To']         =lang('home_To');
		$data['home_Depart']     =lang('home_Depart');
		$data['home_Return']     =lang('home_Return');
		$data['home_Airline']    =lang('home_Airline');
		$data['home_Find']       =lang('home_Find');
		$data['home_oneway']     =lang('home_oneway');
		$data['home_roundtrip']  =lang('home_roundtrip');
		$data['home_Find']		=lang('home_Find');



		$this->load->view('home',$data);
	}
	
	
	
	//获取当前语言
	public function get_lang()
	{
		$data=array();
		$data["area"]=$this->input->get("area");
		$data["language"]=$this->WEB_Language;
		$this->load->view("ajax/language",$data);
	}
	
	//航班查询
	public function flight($type="")
	{
		$this->load->library('encrypt');
		
		if(!$_POST)
		{
			redirect(base_url());
		}	
		$data = array();
	   	$data['css'][0] = '<link rel="stylesheet" type="text/css" href="'.site_url('css/validator.css').'" />';
	   	$data['title'] = $this->WEB_SET["WEB_WebsiteTitle_".lang("curlang")].
	   				$this->WEB_SET["WEB_WelcomeText_".lang("curlang")].'-select flight';

	   	//设置左边选中框的默认值
	   	$data['sFromcitycode']	=$this->input->post("FromCityCode");
	   	$data['sDestcitycode']	=$this->input->post("DestCityCode");
	   	$data['sDepartDate']	=$this->input->post("DepartDate");
	   	$data['sReturnDate']	=$this->input->post("ReturnDate");

		$data["isback"]		=$this->input->post("isback");	//是否回程
		$data["goFlightData"]	=$this->input->post("goFlightData"); //去程航班
		
		//去程航班信息设置
		if($data["goFlightData"]!="")
		{
			$this->load->model("Air_model");
			$argoflight=$this->Air_model->getarrbookinfo($this->encrypt->decode($data["goFlightData"]));
	   		$data['argoflight']=$argoflight[0];
	   		$data["mainCurrency"]	=$this->session->userdata("WEB_mainCurrency");
		}
		

	   	//设置航空公司下拉菜单
	   	$airoption =lang("aircompany");
	   	$airlist['']='=='.lang("home_allairline").'==';

	   	foreach ($airoption as $airid => $airname)
	   	{
	   		$airlist[$airid]=$airid.'-'.$airname;
	   	}

	   	$data['selairline']=form_dropdown('airline', $airlist, '','style="width:164px"');
	   	
	   	if($type=="international")
	   	{
	   		$data["queryaction"]="/home/flight/international";
	   		$data["ajaxaction"]="/international/queryflight";
	   	}else
	   	{
	   		$data["queryaction"]="/home/flight";
	   		$data["ajaxaction"]="/home/queryflight";
	   	}

		$this->load->view('flight',$data);
	}
	//航班查询明细
	public function queryflight()
	{
	
	
		$this->benchmark->mark('query1');
		$this->load->library('encrypt');

		$data = array();
		//查询航班
		$this->load->model('Air_model');
		$arairinfo=array();

		$sFromCity=$this->input->get("FromCity");	//出发城市
		$sDestCity=$this->input->get("DestCity");	//目的城市		
		$sLeaveDate=$this->input->get("LeaveDate");	//航班日期
		$sAirline	=$this->input->get("Airline");		//航空公司
		
		$data["isback"]	=$this->input->get("isback");	//是否回程
		$data["goFlightData"]=$this->input->get("goflightdata"); //去程航班
		$data["DoubleTrip"]=$this->input->get("DoubleTrip");
		$data["isset_rebate"]=$this->WEB_SET["isrebate"];
		
		$isPFD="FD"; //是否使用私有运价；
		if($data["isback"]=="1"){
			
			$argodata=explode("|",$this->encrypt->decode($data["goFlightData"]));
			
			
			$sFromCity=$argodata[6];	//出发城市
			$sDestCity=$argodata[5];	//目的城市		
			$sLeaveDate=$this->input->get("ReturnDate");	//回程航班日期
			$sAirline	=$argodata[0];
			$isPFD	=$argodata[14];	//是否使用私有运价
		}
		
		//$sFromCity="SZX";
		//$sDestCity="SHA";
		//$sLeaveDate="2011-06-17";
		
		$arairinfo=$this->Air_model->avflight($sFromCity,$sDestCity,$sLeaveDate,$sAirline,$data["isback"]=="1",$data["DoubleTrip"],$isPFD);

		$this->benchmark->mark('query2');
		
		//echo $this->benchmark->elapsed_time('query1', 'query2');

		$data['arairinfo']=$arairinfo;
		$this->load->view('ajax/queryflight',$data);
		
		
	}
	
	
	//语言切换
	public function changelang($lang)
	{
		if($lang=="english" || $lang=="sc" || $lang=="zh")
		{
			$this->session->set_userdata("lang",$lang);
		}
		
		$returnurl=site_url($this->input->get("returnurl"))."?";
		
		foreach($_GET as $sname => $svalue)
		{
			$returnurl.=$sname."=".$svalue."&";
		}
		redirect($returnurl);
		
		/*
		if($_POST)
		{
			$data=array();
			$data["LastPost"]=$_POST;
			$data["doaction"]=$returnurl;
			print_r($_POST);
			
			$this->load->view("ajax/dolastpost",$data);	
		}else
		{
			redirect($returnurl);
		}
		*/
		

		//redirect("home");
	}
	
	//发送邮件
	public function sendmail()
	{
		$this->load->model("Order_model");
		$this->Order_model->sendmail("398512708@qq.com","你好","我给你发邮件了");
	}
	
	//获取退改签备注
	public function getTGQNote()
	{
		$airline=$this->input->get("airline");
		$classcode=$this->input->get("classcode");
		
		echo "flyguam:".$airline."-".$classcode;
	}
	
	
}

/* End of file home.php */
/* Location: ./application/controllers/home.php */